package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.AdminNewsDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author jack
 * @data 2024 9:47
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 查询文章列表
     *
     * @return
     */
    @PostMapping("list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto reqDto) {
        return wmNewsService.queryByPageWithConditions(reqDto);
    }

    /**
     * 发布文章
     *
     * @return
     */
    @PostMapping("submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto) {
        return wmNewsService.submit(wmNewsDto);
    }

    /**
     * 文章上下架
     *
     * @param map
     * @return
     */
    @PostMapping("down_or_up")
    public ResponseResult downOrUp(@RequestBody Map<String, Object> map) {
        return wmNewsService.downOrUp(map);
    }

    /**
     * @param adminNewsDto:
     * @return ResponseResult<?>
     * @author 18297
     * @date 2024/1/25 08:28
     * @description 管理端查看文章列表
     */
    @PostMapping("/list_vo")
    public ResponseResult<?> list(@RequestBody AdminNewsDto adminNewsDto) {
        return wmNewsService.list(adminNewsDto);
    }

    /**
     * @param id:
     * @return ResponseResult<?>
     * @author 18297
     * @date 2024/1/25 10:20
     * @description 查看文章详情
     */
    @GetMapping("/one_vo/{id}")
    public ResponseResult<?> getWmNewsById(@PathVariable("id") Integer id) {
        return wmNewsService.getWmNewsById(id);
    }

    @PostMapping("/auth_pass")
    public ResponseResult<?> authPass(@RequestBody AdminNewsDto adminNewsDto) {
        return wmNewsService.ManualReview((short)4,adminNewsDto);
    }

    @PostMapping("/auth_fail")
    public ResponseResult<?> authFail(@RequestBody AdminNewsDto adminNewsDto) {
        return wmNewsService.ManualReview((short)2,adminNewsDto);
    }
}
